package com.malphite.mongodemo.mongo;

import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import com.mongodb.client.model.UpdateOptions;
import com.mongodb.client.model.Updates;
import com.mongodb.client.result.UpdateResult;
import org.bson.Document;
import org.bson.conversions.Bson;
import org.bson.types.ObjectId;

import java.util.Arrays;
import java.util.Date;

public class Mongo3Update {

    public static void main(String[] args) {
        MongoDatabase database = Mongo1Connection.getDataBase("test");
        MongoCollection<Document> places = database.getCollection("places");

        Document query = new Document("name","heme");

        Bson set = Updates.set("name", "home");
        Bson createDate = Updates.currentDate("createDate");
        Bson timestamp = Updates.currentTimestamp("currentTimestamp");
        Bson addToSet = Updates.addToSet("add", "add");
        Bson combine = Updates.combine(Arrays.asList(set, createDate, timestamp, addToSet));
        //UpdateResult updateResult = places.updateOne(query, combine);
        UpdateResult updateResult = places.updateMany(query, combine);
        System.out.println(updateResult.getMatchedCount());
        System.out.println(updateResult.getModifiedCount());
        System.out.println(updateResult.wasAcknowledged());
        System.out.println(updateResult.isModifiedCountAvailable());

        UpdateOptions updateOptions = new UpdateOptions();
        ObjectId objectId = new ObjectId();

        Date date = new Date();
        System.out.println(date.getTime());
        //7164648492231557122
        //1668149771966
    }

}
